app.controller('landOwnerDetailCtl', function($scope, $http, rest, $compile, $location, ngDialog, tipService, user, $state, $window, uiLoad, $rootScope, $ocLazyLoad, $timeout, uploadConf, uploadprefix) {

     $scope.uploadprefix = uploadprefix;
     var token = $window.localStorage.getItem("token");
     $scope.queryParams = {};
     $scope.checkStatus = {};

     if ($window.localStorage.getItem("landlordId")) {
          $scope.landlordId = $window.localStorage.getItem("landlordId");
     }
     if ($window.localStorage.getItem("checkStatus")) {
          $scope.checkStatus = $window.localStorage.getItem("checkStatus");
     }

     console.log($scope.checkStatus);

     $scope.column2 = 0; //分栏
     $scope.maxImgNum = 5; //最大图片数量


     $scope.imgNew = [{
          text: '房东身份证',
          name: 'idCardFrontPhoto',
          value: [],
          photoNum: ""
     }, {
          text: '委托收款人身份证',
          name: 'businessDutyPersonIdCardFrontPhoto',
          value: [],
          photoNum: ""
     }, {
          text: '房产证复印件/有效期15天内产调',
          name: 'propertyCopies',
          value: [],
          photoNum: ""
     }, {
          text: '委托代理人授权书',
          name: 'entrustProxyAuthorization',
          value: [],
          photoNum: ""
     }, {
          text: '房东征信授权书',
          name: 'personalCreditAuthorization',
          value: [],
          photoNum: ""
     }, {
          text: '房屋综合管理服务协议',
          name: 'houseManageContract',
          value: [],
          photoNum: ""
     }, 
     // {
     //      text: '房东收租流水',
     //      name: 'rentStream',
     //      value: [],
     //      photoNum: ""
     // },
      {
          text: '其他影像资料',
          name: 'otherImageData',
          value: [],
          photoNum: ""
     }];
     uploadConf.column2 = $scope.column2;
     uploadConf.maxImgNum = $scope.maxImgNum;
     uploadConf.imgNew = $scope.imgNew;

     applyLandlordDetail();

     function applyLandlordDetail() {
          rest.decoJava({
               type: "post",
               url: "/tenancy-sys/landlord/queryLandlordById",
               data: {
                    landlordId: $scope.landlordId,
               },
               beforeSend: function(request) {
                    request.setRequestHeader("token", token);
               },
               success: function(data) {
                    if (data.code == 0) {
                         $scope.$apply(function() {
                              $scope.queryParams = data.result;
                         })
                         $scope.rejectReason = $scope.queryParams.rejectReason;

                         if ($scope.queryParams.landlordType == "PERSON") {
                              $scope.queryParams.landlordType = "职业房东（个人）";
                         } else if ($scope.queryParams.landlordType == "ENTERPRISE") {
                              $scope.queryParams.landlordType = "职业房东（企业）";
                         } else {
                              $scope.queryParams.landlordType = "业主（产权拥有）";
                         }



                         //判断是否是指派过的房源
                         if ($scope.queryParams.pointPerson == null || $scope.queryParams.pointPerson == '') {
                              $scope.assigned = 0;
                         } else {
                              $scope.assigned = 1;
                         }

                         if ($scope.queryParams.checkStatus == "RETURNBACK") {
                              $scope.statusStr = "回退补件";
                         } else if ($scope.queryParams.checkStatus == "CHECKSUCCESS") {
                              $scope.statusStr = "审核通过";
                         } else if ($scope.queryParams.checkStatus == "INREVIEW") {
                              $scope.statusStr = "审核中";
                         } else if ($scope.queryParams.checkStatus == "CHECKFAILE") {
                              $scope.statusStr = "审核未通过";
                         } else {
                              $scope.statusStr = "房东待审核";
                         }

                         // if($scope.queryParams.checkStatus == "UNCHECK" && $scope.queryParams.pointPerson != null && $scope.queryParams.pointPerson != ''){
                         //      $("input").removeAttr("readonly");
                         //      $(".details-tr td input").css("background-color","#fff")

                         // }

                         var pushPhoto = function(photoString) {
                              var photoVals = [];
                              if (photoString && photoString.length > 0) {
                                   photoVals = photoString.split(",");
                              }
                              return photoVals;
                         }

                         // $scope.imgNew[0].value = [$scope.queryParams.idCardFrontPhoto, $scope.queryParams.idCardContraryPhoto];
                         // $scope.imgNew[1].value = [$scope.queryParams.businessDutyPersonIdCardFrontPhoto, $scope.queryParams.businessDutyPersonIdCardContraryPhoto];
                        
                         var img1 = [];
                         if ($scope.queryParams.idCardFrontPhoto) {
                              img1.push($scope.queryParams.idCardFrontPhoto);
                         }
                         if ($scope.queryParams.idCardContraryPhoto) {
                              img1.push($scope.queryParams.idCardContraryPhoto);
                         }

                         var img2 = [];
                         if ($scope.queryParams.businessDutyPersonIdCardFrontPhoto) {
                              img2.push($scope.queryParams.businessDutyPersonIdCardFrontPhoto);
                         }
                         if ($scope.queryParams.businessDutyPersonIdCardContraryPhoto) {
                              img2.push($scope.queryParams.businessDutyPersonIdCardContraryPhoto);
                         }


                         $scope.imgNew[0].value = img1;
                         $scope.imgNew[1].value = img2; 
                         
                         $scope.imgNew[2].value = pushPhoto($scope.queryParams.propertyCopies);
                         $scope.imgNew[3].value = pushPhoto($scope.queryParams.entrustProxyAuthorization);
                         $scope.imgNew[4].value = pushPhoto($scope.queryParams.personalCreditAuthorization);
                         $scope.imgNew[5].value = pushPhoto($scope.queryParams.houseManageContract);
                         // $scope.imgNew[6].value = pushPhoto($scope.queryParams.rentStream);
                         $scope.imgNew[6].value = pushPhoto($scope.queryParams.otherImageData);

                         $scope.$apply();
                         uploadConf.imgNew = $scope.imgNew;
                         console.log(uploadConf);
                    } else {
                         tipService.show("body", {
                              message: data.message,
                              notice: "danger"
                         }, 3);
                    }

               }
          });
     }

     $("#suggest").on("input propertychange", function() {
          var $this = $(this),
               _val = $this.val(),
               count = "";
          if (_val.length > 200) {
               $this.val(_val.substring(0, 200));
          }
          count = 200 - $this.val().length;
          $("#text-count").text(count);
     });

     $(document).ready(function() {

          function myfunction(li, li_a, menu_tab) {
               li.click(function() {
                    var index = $(this).index();
                    menu_tab.eq(index).addClass("active").siblings().removeClass("active");
                    li_a.removeClass("selected");
                    li_a.eq(index).addClass("selected").siblings().removeClass("selected");

               });
          }

          myfunction($(".container .menu .ulmenu1 li"), $(".container .ulmenu1 li a"), $(".container .content .menu1 .tab"));
          myfunction($(".container .menu .ulmenu2 li"), $(".container .ulmenu2 li a"), $(".container .content .menu2 .tab"));
          myfunction($(".container .menu .ulmenu3 li"), $(".container .ulmenu3 li a"), $(".container .content .menu3 .tab"));


          // var li1=$(".container .menu ul li");
          // var lia=$(".container .menu ul li a");
          // var tab1=$(".container .content .menu1 .tab ");

          // li1.click(function(){
          //   var index=$(this).index();

          //   tab1.eq(index).addClass("active").siblings().removeClass("active");
          //   lia.removeClass("selected");
          //   lia.eq(index).addClass("selected").siblings().removeClass("selected");
          // });

          $(function() { //ul/li的折叠效果
               $(".menu > ul").eq(0).show();
               $(".menu h3").click(function() {
                    //找menu对应的tab
                    $(".menu_tab > div").removeClass("active");

                    var val = ($(this).next().attr('class'));
                    var menu_value = (val.substring(val.length - 1));
                    $(".container .content .menu" + menu_value + " .tab:first-child").addClass("active");
                    $(".container .menu .ulmenu" + menu_value + " li>a").removeClass("selected");
                    $(".container .menu .ulmenu" + menu_value + " li a").eq(0).addClass("selected"); //默认设置为被选中状态


                    // $("."+"val").child().child().("selected")

                    //这是ul收缩效果
                    $(this).next().stop().slideToggle();
                    $(this).siblings().next("ul").stop().slideUp();

                    // if($(".container .ulmenu"+menu_value+" li ").find("a").attr("class")==="selected"){
                    //        $(".container .content .menu"+menu_value+" .tab:first-child")
                    // }
               });

          });

          $(function() { // 导航 >
               $(".container .menu > h3").click(function() {

                    $(".container .content .A1").empty().text($(this).text());

               });
          });
     });


     // 查看流转记录

     $scope.viewRecord = function() {
          ngDialog.openConfirm({
               template: 'views/landlord/viewLandRecord.html',
               resolve: {
                    load: function() {
                         return $ocLazyLoad.load('angularFileUpload').then(
                              function() {
                                   return uiLoad.load(['js/controllers/landlord/viewLandRecord.js'])
                              });
                    }
               },
               data: {
                    landlordId: $scope.queryParams.id,
               },
               scope: $scope,
               width: 900,
               // height: 700
          }).then(function(data) {

          }, function(reason) {

          });
     }

     $scope.claimLandlord = function() {
          ngDialog.openConfirm({
               template: 'js/module/fund/claimLandlord.html',
               resolve: {
                    load: function() {
                         return $ocLazyLoad.load('angularFileUpload').then(
                              function() {
                                   return uiLoad.load(['js/module/fund/claimLandlord.js'])
                              });
                    }
               },
               data: {
                    landlordId: $scope.landlordId,
                    // pointPersonId:$scope.queryParams.pointPerson,
               },
               scope: $scope,
               width: 600,
               // height: 700
          }).then(function(data) {

          }, function(reason) {
               applyLandlordDetail();
          });
     }


     $scope.assignToLandlord = function(id) {
          ngDialog.openConfirm({
               template: 'js/module/fund/assignToLand.html',
               resolve: {
                    load: function() {
                         return uiLoad.load(['js/module/fund/assignToLand.js'])
                    }
               },
               data: {
                    landlordId: id
               },
               scope: $scope,
               width: 600,
               // height: 700
          }).then(function(data) {
               $scope.coverBgHide();
          }, function(reason) {
               applyLandlordDetail();
          });
     }


     //回退补件
     $scope.fallback = function() {

          rest.decoJava({
               type: "post",
               url: "/tenancy-sys/landlord/submitReview",
               // data: $scope.queryParams,
               data: {
                    id: $scope.landlordId,
                    checkStatus: 'RETURNBACK',
                    rejectReason: $scope.rejectReason


               },
               beforeSend: function(request) {
                    request.setRequestHeader("token", token);
               },
               success: function(data) {
                    if (data.code == 0000) {
                         tipService.show("body", {
                              message: data.message,
                         }, 3);
                         // $state.go('app.landlord.landlordManage');
                    } else {
                         tipService.show("body", {
                              message: data.message,
                              notice: "danger"
                         }, 3);
                         return;
                    }
               }
          });
     }

     //通过
     $scope.passThrough = function() {
          rest.decoJava({
               type: "post",
               url: "/tenancy-sys/landlord/submitReview",
               // data: $scope.queryParams,
               data: {
                    id: $scope.landlordId,
                    checkStatus: 'CHECKSUCCESS',
                    rejectReason: $scope.rejectReason

               },
               beforeSend: function(request) {
                    request.setRequestHeader("token", token);
               },
               success: function(data) {
                    if (data.code == 0000) {
                         tipService.show("body", {
                              message: data.message,
                         }, 3);
                         // $state.go('app.landlord.landlordManage');
                    } else {
                         tipService.show("body", {
                              message: data.message,
                              notice: "danger"
                         }, 3);
                         return;
                    }
               }
          });
     }



});